package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.JsonResult;
import com.gxan.service.HumanService;
import com.gxan.service.impl.HumanServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/search")
public class SearchHumanServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取前端传递字段
        String human_name = request.getParameter("human_name");
        Integer currentPage = Integer.parseInt(request.getParameter("page"));
        Integer pageSize = Integer.parseInt(request.getParameter("limit"));
        //2.调用service
        HumanService humanService = new HumanServiceImpl();
        JsonResult jsonResult = humanService.queryHumanList(currentPage, pageSize, human_name);

        //3.响应
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(jsonResult));
        response.getWriter().flush();
        response.getWriter().close();

    }
}
